﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_user_edit.aspx.cs" Inherits="Ccit.SysPlat.Organ.sys_user_edit" %>
<%@ Register TagPrefix="ccit" Assembly="Ccit.ServerControls.ActionForm" Namespace="Ccit.ServerControls" %>
<html>
<head runat="server">
    <title>用户信息维护</title>
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/jsonlib.js"></script>
    <script type="text/javascript" src="../script/jcontrol.js"></script>
    <script type="text/javascript">
    <!--
        function doCheck(vType) {
            switch (vType) {                
                case "LOGINNAME":
                    var oCtrlLoginName = $get("txtLgName");
                    var vUserId = $get("_hidUserId").value;
                    var vLoginName = jQuery.trim(oCtrlLoginName.value);
                    /* 校验是否重复 */
                    if (vLoginName != "") {
                        PageMethods.CheckLoginNameExist(vUserId, vLoginName, ClientCallBack);
                    }
                    break;
            }
        }


        function ClientCallBack(vResult) {
            if (null == vResult || vResult == "undefined") {
                alert("网络传输错误,没有正确的返回值,请检查网络是否畅通!");
                return;
            }
            eval("var resultObj=" + vResult);
            var operType = resultObj.OPERTYPE;
            switch (operType) {                
                case "LGNAMECHECK":
                    if (resultObj.RSTSIGN == "EXIST") {
                        alert(resultObj.RSTMSG);
                        var oCtrlLoginName = $get("txtLgName");
                        oCtrlLoginName.focus();
                    }
                    break;
                case "USERSAVE":  //用户信息保存
                    var ctrlType = resultObj.CTRLTYPE;  //操作按钮控件的类型(保存,保存新增,保存返回)     
                    alert(resultObj.RSTMSG);
                    if (parseInt(resultObj.RSTSIGN) > 0) {
                        switch (ctrlType) {
                            case "1":
                                $get("_hidUserId").value = resultObj.RSTSIGN;
                                break;
                            case "2":
                                initAddNew();
                                break;
                            case "3":
                                doBack();
                                break;
                        }
                    }                   
                    break;
            }
            resultObj = null;            
        }

        function checkform() {
            var oCtrlUserName = $get("txtUserName");
            var vUserName = oCtrlUserName.value;
            /* 用户姓名不能为空 **/
            if (jQuery.trim(vUserName) == "") {
                alert("用户姓名不能为空!")
                oCtrlUserName.focus();
                return false;
            }
            var oCtrlLoginName = $get("txtLgName");
            if (jQuery.trim(oCtrlLoginName.value) == "") {
                alert("登陆名不能为空!");
                oCtrlLoginName.focus();
                return false;
            }
            return true;
        }

        function doSave(vCtrlType) {
            if (!checkform()) return;
            SaveUser(vCtrlType);
        }

        function SaveUser(ctrlType) {
            var msUser = {};
            msUser.userId = $get("_hidUserId").value;
            msUser.loginName = jQuery.trim($get("txtLgName").value);
            msUser.userName = jQuery.trim($get("txtUserName").value);
            msUser.userCode = jQuery.trim($get("txtUserCode").value);

            // get epass
            var ukEffect = $get("_hidSysUK").value;
            if (ukEffect == "0") {
                msUser.ePassSign = "0";
                msUser.ePass = "";
            }
            else {
                msUser.ePassSign = $get("rdlist").options[$get("rdlist").selectedIndex].value;
                msUser.ePass = jQuery.trim($get("txtUseKey").value);
            }

            var msOrgan = {};
            msOrgan.organId = $get("_hidOrganId").value;

            var msDept = {};
            var msPos = {};
            // get dept and position
            var multiDept = $get("_hidSysMultiDept").value;
            if (multiDept == "0") {
                msDept.deptId = $get("_hidSinDeptId").value;
                msPos.posId = $get("_hidSinPosId").value;
            }
            else {
                // logic code vacancy
            }

            var msCls = {};
            msCls.clsId = $get("_hidSinClsId").value;

            msUser.belongOrgan = msOrgan;
            msUser.belongDept = msDept;
            msUser.belongPos = msPos;
            msUser.belongClass = msCls;

            var jsonExpr = JSON.stringify(msUser, function(key, value) { return value; });
            PageMethods.SaveUserData(jsonExpr, ctrlType, ClientCallBack);

            msUser = null;
        }

        function doBack() {
            var vOrganId = $get("_hidOrganId").value;
            var vPageParam = "organid=" + vOrganId;
            var encodeParam = base64encode(vPageParam);
            var strURL = "./sys_user_frame.aspx?" + encodeParam;
            document.location.href = strURL;
        }

        function doDeptIndexChange() {
            var ddlDept = new DropDownList("ddlDept");            
            $get("_hidSinDeptId").value = ddlDept.selectedValue;
            ddlDept = null;
        }

        function doPosIndexChange() {
            var ddlPos = new DropDownList("ddlPos");            
            $get("_hidSinPosId").value = ddlPos.selectedValue;
            ddlPos = null;
        }

        function doClassIndexChange() {
            var ddlClass = new DropDownList("ddlClass");            
            $get("_hidSinClassId").value = ddlClass.selectedValue;
            ddlClass = null;
        }
        function initAddNew() {
            $get("_hidUserId").value = "";
            $get("_hidSinDeptId").value = "";
            $get("_hidSinPosId").value = "";
            $get("_hidSinClsId").value = "";
            __doPostBack("lnbCallBack", "");

        }

        function doMultiDept(vCtrlId, vCtrlName) {
            OpenDeptMultiSelect(vCtrlId, vCtrlName, "1");
        }

        function doMultiPos(vCtrlId, vCtrlName) {
            OpenPosMultiSelect(vCtrlId, vCtrlName, "1");
        }
    //-->
    </script>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">    
    <input type="hidden" id="_hidOrganId" runat="server" />
    <input type="hidden" id="_hidUserId" runat="server" />
    <input type="hidden" id="_hidInsetSign" runat="server" />
    <input type="hidden" id="_hidSysUK"  runat="server" />
    <input type="hidden" id="_hidSysMultiDept" runat="server" />
    <input type="hidden" id="_hidSinDeptId" runat="server" />
    <input type="hidden" id="_hidSinPosId" runat="server" />
    <input type="hidden" id="_hidSinClsId" runat="server" />
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <table id="tblToolbar" class="tbToolbar" cellpadding="0" cellspacing="0" width="98%" align="center">
            <tr>
                <td align="left">
                    <div class="tbSeparator"></div>
                </td>
                <td width="100%" class="titlebar">
                    系统管理 - > 用户信息编辑
                </td>
                <td align="right">
                    <div class="tbSeparatorEnd"></div>
                </td>
            </tr>
        </table>
        <table class="tableborder" cellpadding="0" cellspacing="0" width="98%" align="center">
            <tr>
                <td width="8%" align="center" class="pformleft"><nobr><font color='red'>*</font>用户姓名</nobr></td>
                <td width="17%" class="pformrightline">
                    <asp:TextBox ID="txtUserName" onblur="doCheck('USERNAME')" CssClass="input" Width="98%" runat="server"></asp:TextBox>
                </td>
                <td width="8%" align="center" class="pformleft"><nobr>用户编号</nobr></td>
                <td width="17%" class="pformrightline">
                    <asp:TextBox ID="txtUserCode" CssClass="input" Width="98%" runat="server"></asp:TextBox>
                </td>
                <td width="8%" align="center" class="pformleft"><nobr><font color='red'>*</font>登录名</nobr></td>
                <td width="17%" class="pformrightline">
                    <asp:TextBox ID="txtLgName" onblur="doCheck('LOGINNAME')" CssClass="input" Width="98%" runat="server"></asp:TextBox>
                </td>
                <td width="25%" align="left" class="pformleft" colspan="2">
                    <font color="blue" face='Arial'>登陆默认口令为: kkkkkk</font>
                </td>
            </tr>
            <tr>
                <td width="8%" align="center" class="pformleft"><nobr>级别</nobr></td>
                <td width="17%" class="pformrightline">                   
                    <asp:DropDownList ID="ddlClass" onchange="doClassIndexChange()" CssClass="select" Width="98%" runat="server"></asp:DropDownList>
                </td>
                <td width="8%" align="center" class="pformleft"><nobr>身份认证锁</nobr></td>
                <td width="17%" class="pformrightline">
                    <asp:RadioButtonList ID="rdlist" CssClass="radio" runat="server" RepeatDirection="Horizontal">
                        <asp:ListItem Value="0">不启用</asp:ListItem>
                        <asp:ListItem Value="1">启用</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td width="8%" align="center" class="pformleft"><nobr>身份Key</nobr></td>
                <td colspan="3" width="42%" class="pformright">
                    <asp:TextBox ID="txtUseKey" CssClass="input" Width="98%" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr id="trSingle" runat="server">
                <td width="8%" class="pformleft" align="center"><nobr>部门</nobr></td>
                <td colspan="3" width="42%" class="pformrightline">                    
                    <asp:DropDownList ID="ddlDept" onchange="doDeptIndexChange()" CssClass="select" Width="98%" runat="server"></asp:DropDownList>
                    
                </td>
                <td width="8%" class="pformleft" align="center"><nobr>职位</nobr></td>
                <td colspan="3" width="42%" class="pformright">                    
                    <asp:DropDownList ID="ddlPos" onchange="doPosIndexChange()" CssClass="select" Width="98%" runat="server"></asp:DropDownList>               
                </td>
            </tr>
            <tr id="trMulti" runat="server">
                <td width="8%" class="pformleft" align="cennter" valign="top">
                <nobr>
                    <a href="javascript:doMultiDept('_hidDeptId','txtDeptName')">部门
                        <img src="../images/toolbar/select.gif" border="0" />
                    </a>
                </nobr></td>
                <td colspan="3" width="42%" class="pformrightline">
                    <asp:TextBox ID="txtDeptName" TextMode="MultiLine" CssClass="input" runat="server" Width="98%" Height="80px"></asp:TextBox>
                    <input type="hidden" id="_hidDeptId" runat="server" />                    
                </td>
                <td width="8%" class="pformleft" align="cennter" valign="top">
                <nobr>
                    <a href="javascript:doMultiPos('_hidPosId','txtPosName')">职位
                        <img src="../images/toolbar/select.gif" border="0" />
                    </a>
                </nobr></td>
                <td colspan="3" width="42%" class="pformrightline">
                    <asp:TextBox ID="txtPosName" TextMode="MultiLine" CssClass="input" runat="server" Width="98%" Height="80px"></asp:TextBox>
                    <input type="hidden" id="_hidPosId" runat="server" />                    
                </td>
            </tr>
            <tr id="trOper" class="pformstrip">
                <td colspan="8" align="center">
                    <input type="button" id="btnSave" class="button" value="保存" onclick="doSave('1')" />
                    &nbsp;
                    <input type="button" id="btnSaveAdd" class="button" value="保存并新增" onclick="doSave('2')" />                    
                    &nbsp;
                    <input type="button" id="btnSaveBack" class="button" value="保存并返回" onclick="doSave('3')" />                    
                    &nbsp;
                    <input type="button" id="btnBack" class="button" value="返回" onclick="doBack()" />                    
                </td>               
            </tr>
        </table>
        <asp:LinkButton ID="lnbCallBack" style="display:none" runat="server" onclick="lnbCallBack_Click"></asp:LinkButton>
    </ccit:ActionForm>
    
    <script type="text/javascript">
    <!--
          $(document).ready(function() {
              var vInset = $get("_hidInsetSign").value;
              if (vInset == "1") {
                  $get("tblToolbar").style.display = "none";
                  $get("trOper").style.display = "none";
              }
          });
    //-->
    </script>
</body>
</html>
